<?php
header("content-type:text/html;charset=utf-8");
include "../public/config/config.php";
include "../public/include/funcs.php";

$id = $_GET['id'];
//$id = 60014;
$link=conn($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname,$cfg_dbchar);

$time = date("Y-m-d");
$time_arr = explode("-", $time);
$y = $time_arr[0];
$m = $time_arr[1];
//$m = "12";
$yy = $y;
$mm = $m + 1;
if($mm < 10){
	$mm = "0".$mm;
}
if($mm == 13){
	$yy = $y + 1;
	$mm = "01";
}
$time_start = strtotime($y."-".$m);
$time_end = strtotime($yy."-".$mm);
$arr = select($link, "award", "u_id=$id and int_time>$time_start and int_time<$time_end");
if($arr){
	mysqli_close($link);
	echo 0;
}else{
	$award = [
		"0",
		"169元陶瓷养生锅",
		"很遗憾，请再接再厉",
		"39元毛绒玩具",
		"20M流量",
		"很遗憾，请再接再厉",
		"39元毛绒玩具",
		"20M流量",
		"很遗憾，请再接再厉"
	];
	$num = mt_rand(1, 8);
	$add_arr['u_id'] = $id;
	$add_arr['at_id'] = 1;
	$add_arr['award'] = $award[$num];
	$add_arr['int_time'] = time();
	$re = add($link, "award", $add_arr);
	if($re){
		echo $num;
	}else{
		echo 999;
	}
}


?>